#if defined(_WIN32)
#include "commonWin.h"
#include "log4z.h"

LPCWSTR ConvertCharToLPCWSTR(const char* inputString) {
	int inputStringLength = strlen(inputString) + 1; // Include null terminator

	// Convert char* to wchar_t*
	int bufferSize = MultiByteToWideChar(CP_UTF8, 0, inputString, inputStringLength, NULL, 0);
	wchar_t* wideString = new wchar_t[bufferSize];
	MultiByteToWideChar(CP_UTF8, 0, inputString, inputStringLength, wideString, bufferSize);

	// Use wideString as LPCWSTR
	LPCWSTR lpcwStr = wideString;

	// Clean up
	delete[] wideString;

	return lpcwStr;
}

std::string ConvertWCHARToString(const WCHAR* wideString) {
	// Get the length of the wide string
	int length = wcslen(wideString);

	// Allocate a buffer for the converted string
	char* buffer = new char[length + 1];

	// Convert wide string to multibyte string
	WideCharToMultiByte(CP_UTF8, 0, wideString, -1, buffer, length + 1, NULL, NULL);

	// Create a std::string from the converted string
	std::string result(buffer);

	// Clean up
	delete[] buffer;

	return result;
}

LPCWSTR CharToLPCWSTR(const char* charString) {
	// 计算需要的缓冲区大小
	int size = MultiByteToWideChar(CP_UTF8, 0, charString, -1, NULL, 0);

	// 分配缓冲区
	wchar_t* wideString = new wchar_t[size];

	// 进行转换
	MultiByteToWideChar(CP_UTF8, 0, charString, -1, wideString, size);

	// 返回宽字符字符串
	return wideString;
}

std::string WCHARToString(const WCHAR* wideString) {
	// 获取宽字符字符串的长度
	int wideLength = wcslen(wideString);

	// 计算需要的缓冲区大小（不包括结尾的空字符）
	int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wideString, wideLength, nullptr, 0, nullptr, nullptr);

	// 分配缓冲区
	char* buffer = new char[bufferSize + 1];  // 加一用于存放结尾的空字符

	// 进行转换
	WideCharToMultiByte(CP_UTF8, 0, wideString, wideLength, buffer, bufferSize, nullptr, nullptr);

	// 添加结尾的空字符
	buffer[bufferSize] = '\0';

	// 将转换后的字符串存入 std::string 中
	std::string result(buffer);

	// 释放动态分配的内存
	delete[] buffer;

	return result;
}

#endif